<?php
// +---------------------------------------------------------------------------+
// | This file is part of the KnowledgebasePublisher package                   |
// | KnowledgebasePublisher - web based knowledgebase publisher tool           |
// |                                                                           |
// | Author:  Evgeny Leontev <eleontev@gmail.com>                              |
// | Copyright (c) 2005 Evgeny Leontev                                         |
// |                                                                           |
// | For the full copyright and license information, please view the LICENSE   |
// | file that was distributed with this source code.                          |
// +---------------------------------------------------------------------------+


class LetterTemplateView_list extends AppView
{
	
	var $template = 'list.html';
	
	
	function execute(&$obj, &$manager) {

		$this->addMsg('common_msg.ini', 'email_setting');
	
		$tpl = &new tplTemplatez($this->template_dir . $this->template);
		
		// header generate
		$bp = &$this->pageByPage($manager->limit, $manager->getRecordsSql());
		$tpl->tplAssign('header', $this->commonHeaderList($bp->nav, false, false));
		
		// sort generate
		$sort = &$this->getSort();
		$manager->setSqlParamsOrder($sort->getSql());
		
		// get records
		$rows =& $this->stripVars($manager->getRecords($bp->limit, $bp->offset));
		$msg = AppMailParser::getTemplateMsg();
		
		// list records
		foreach($rows as $row) {

			$obj->set($row);
			if(!$obj->get('title')) {
				$obj->set('title', $msg[$row['letter_key']]['title']);
			}
			
			$tpl->tplAssign($this->getViewListVars($obj->get('id'), 
													$obj->get('active'), 
													$obj->get('predifined'),
													$obj->get('in_out')));
			$tpl->tplParse(array_merge($obj->get(), $this->msg), 'row');
		}
		
		$tpl->tplAssign($this->msg);
		$tpl->tplAssign($sort->toHtml());
		
		$tpl->tplParse();
		return $tpl->tplPrint(1);
	}
	
	
	function &getSort() {
		//$sort = new TwoWaySort();
		$sort = new OneWaySort($_GET);
		$sort->default_order = 2;
		$sort->setTitleMsg('asc',  $this->msg['sort_asc_msg']);
		$sort->setTitleMsg('desc', $this->msg['sort_desc_msg']);
		$sort->setSortItem('title_msg',  'title', 'title', $this->msg['title_msg'], 1);
		$sort->setSortItem('status_msg','status', 'active', $this->msg['status_msg']);
		
		//$sort->getSql();
		//$sort->toHtml()
		return $sort;
	}
	
	
	function getViewListVars($record_id = false, $active = false, $predifined = false, $in_out = false) {
		$row = parent::getViewListVars($record_id, $active);
		
		if($in_out == 1) {
			$row['in_out_img'] = $this->getImgLink(false, 'arrow_f', '');
		} else {
			$row['in_out_img'] = $this->getImgLink(false, 'arrow_b', '');
		}
		
		if($predifined) { 
			$row['delete_img']	= ''; 
		}
		
		return $row;
	}
}
?>